# coding=utf-8
import gzip
import difflib

def main():
	data = gzip.GzipFile('deltas.gz').read()
	data = data.splitlines()
	left, right, png = [], [], ['', '', '']
	for line in data:
		left.append(line[:53])
		right.append(line[56:])
	diff = list(difflib.ndiff(left, right))# 调用difflib模块的ndiff比较2个字符串列表，返回的每行开头为'- '或'+ '或'  '，分别表示对左唯一还是对右唯一还是两边都包涵。

	for line in diff:
		bytes = [chr(int(byte, 16)) for byte in line[2:].split()]
		if line[0] == '+':
			png[0] += ''.join(bytes)
		elif line[0] == '-':
			png[1] += ''.join(bytes)
		elif line[0] == ' ':
			png[2] += ''.join(bytes)
	for i in range(3):
		open("output%s.png"%i, "wb").write(png[i])
	# 分别是butter, fly, ../hex/bin.html

if __name__ == '__main__':
	main()
